/**
 * 
 */
package org.istt.dao;

import java.util.Date;
import java.util.List;

import org.displaytag.properties.SortOrderEnum;
import org.istt.domain.AttachFileDetail;
import org.istt.domain.Exchange;
import org.istt.domain.File;
import org.istt.domain.FileManagement;
import org.istt.model.FileView;

/**
 * @author Huy
 *
 */
public interface FileDao extends Dao<File, String> {
	/**
	 * Get list of file belongs to a category
	 * @param catId category ID
	 * @return list of file
	 */
	List<File> findByCatId(Long catId);
	
	/**
	 * Get list of file with criteria as follows
	 * @param cateId category ID
	 * @param fromDate
	 * @param toDate
	 * @return list of file
	 */
	List<File> find(Long cateId, Date fromDate, Date toDate);

	List<File> findTrans(Long fieldId, Long cateId, String fileId, String sender);

	
	/**
	 * Get list of file with category ids
	 * @param fileIds 
	 * @return list of file
	 */
	List<List<Object>> findByFileIds(String[] fileIds);
	
	/**
	 * Get workflow identity of a file
	 * @param fileId file identity
	 * @return workflow identity
	 */
	Long getWorkFlowId(String fileId);
	
	/**
	 * Get list of file by status
	 * @param status 
	 * @return list of file
	 */
	List<File> findByStatus(int status, int firstResult, int maxResults,
            SortOrderEnum sortDirection, String sortCriterion);
	/**
	 * 
	 * @param status
	 * @return
	 */
	int findByStatusRecordsCount(int status);
	
	
	/**
	 * 
	 * @param cateId
	 * @param fromDate
	 * @param toDate
	 * @return
	 */
	int getSearchRecordCount(Integer type, Long departmentId, Long fileStatusId, Long fieldId, Long cateId, Date fromDate, Date toDate, String fileId, String sender );
	
	/**
	 * 
	 * @param cateId
	 * @param fromDate
	 * @param toDate
	 * @param firstRecordIndex
	 * @param pageSize
	 * @param sortDirection
	 * @param sortCriterion
	 * @return
	 */
	List<File> search(Integer type, Long departmentId, Long fileStatusId, Long fieldId, Long cateId, Date fromDate, Date toDate, String fileId, String sender, int firstResult, int maxResults,
			SortOrderEnum sortDirection, String sortCriterion);

	List<File> searchWithoutPagination(Long departmentId, Long fileStatusId, Long fieldId, Long cateId, Date fromDate, Date toDate, String fileId, String sender);

	/***
	 * Tra cuu danh sach ho so 
	 * Phuc vu Webservice
	 * @param cateId
	 * @param fromDate
	 * @param toDate
	 * @param fileId
	 * @param sender
	 * @return
	 */
	List<File> searchFile(Long cateId, Date fromDate, Date toDate, String fileId, String sender, int page);
	
	/**
	 * Get list of ordered exchange by fileId
	 * @param status 
	 * @return list of exchange
	 */
	List<Exchange> findExchangeByFileId(String fileId, Long userId);
	/**
	 * Get list of ordered fileManagement by fileId
	 * @param status 
	 * @return list of FileManagement
	 */
	List<FileManagement> findFileManagementByFileId(String fileId, String username);
	
	/**
	 * 
	 * @param fileId
	 * @return
	 */
	List<AttachFileDetail> getAttachFileDetailByFileId(String fileId);
	
	/***
	 * Created on 2012.03.29
	 * Get all attachment file belong to a file
	 * @param fileId
	 * @return
	 */
	List<AttachFileDetail> findAttachFileDetailByFileId(String fileId);
	
	/**
	 * 
	 * @param fileId
	 */
	void removeAttachFileDetail(String fileId);
	
	List<File> getFilesForReport(Long cateId,Long subCateId, Date fromDate, Date toDate);
	
	List<Object[]> getFileProcessVoucher(String fileId);

	List<File> findByCodeAndName(String fileCode,String sender);
	
	List<FileView> findFileByApprover(Long userId, Date fromDate, Date toDate, String status,String filterConditional,int firstRecordIndex, int pageSize,
			SortOrderEnum sortDirection, String sortCriterion);
	/*
	 * Created by NDTHO.2012.02.14
	 */
	int getRecordCountByFilterCondition(Long userId,  Date fromDate, Date toDate, String status,String filterCondition);
	
	/**
	 * Get all the files were handled by user
	 * @param userId
	 * @param firstRecordIndex
	 * @param pageSize
	 * @param sortDirection
	 * @param sortCriterion
	 * @return the list of files
	 */
	List<FileManagement> getFileByUser(Long userId, Date fromDate, Date toDate, int firstRecordIndex, int pageSize,
			SortOrderEnum sortDirection, String sortCriterion);
	
	/**
	 * Get the number of files were handled by user
	 * @param userId
	 * @return the number of file
	 */
	int getFileByUserRecordCount(Long userId, Date fromDate, Date toDate);
	
	List<FileView> findFileByDepartment(Long departmentId, String status,int firstRecordIndex, int pageSize,
			SortOrderEnum sortDirection, String sortCriterion);
	
	int getRecordCountByDepartment(Long departmentId, String status);
	
	int checkNewFileByApprover(Long userId,Date fromDate,Date toDate,boolean status);

	/**
	 * whether the current file management handed by user and file or not
	 * @param fileId the file identity
	 * @param username the user-name
	 * @return <code>true</code> if the user can move to next step, otherwise <code>false</code>
	 */
	boolean isAbleToNextStep(String fileId, String username);
	
	/**
	 * Get the max of the number field 
	 * @return the max of the number field
	 */
	int getMaxNumberNoOfFile(Long fieldId, int reportStartingPoint);
	
	/**
	 * Get number of file on the 13th of this month
	 * @return number of file
	 */
	int getNumberOfFileOnReportDate(Long fieldId,int reportStartingPoint);
	
	List<FileManagement> getHistoryByUser(Long userId,Date from, Date to,int firstRecordIndex, int pageSize, 
			SortOrderEnum sortDirection, String sortCriterion);
	
	int getHistoryCountByUser(Long userId, Date from, Date to);
	
	List<File> findFileByDepartmentByDate(Long deptId, Date from, Date to);
	
	/**
	 * Remove all the files its identity is specified in the parameters
	 * @param ids id parameter
	 */
	void remove(String[] ids);

	void removeAllFile();

	void removeAllDataTable();
	
}
